package net.stuffrepos.bricknetcenter.http;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public interface HttpParser {

    public void parse(HttpResponse response) throws Exception;

    public static enum ValueType {

        String(new StringConverter());

        public static ValueType byObject(Object object) {
            if (java.lang.String.class.equals(object.getClass())) {
                return ValueType.String;
            } else {
                throw new IllegalArgumentException(object.getClass() + " is not mapped");
            }
        }

        private ValueType(Converter converter) {
            this.converter = converter;
        }
        private Converter converter;

        public String objectToString(Object object) {
            return converter.objectToString(object);
        }

        public Object stringToObject(String string) {
            return converter.stringToObject(string);
        }

        private static interface Converter {

            public String objectToString(Object object);

            public Object stringToObject(String string);
        }

        private static class StringConverter implements Converter {

            @Override
            public java.lang.String objectToString(Object object) {
                return object == null ? null : object.toString();
            }

            @Override
            public Object stringToObject(java.lang.String string) {
                return string;
            }
        }
    }
}
